function z = kendtauz(varargin)
% kendtaut  - give approximate z-score for kendall tau (via formula)
%
% FORMAT:       z = kendtauz(v, m [, d])
%
% Input fields:
%
%       v           vector for which tau was computed
%       m           matrix (either VxM or MxV)
%       d           dim of m to use to build pairs, default: first match
%
% Output fields:
%
%       z           approximate z-score
%
% Notes: See references of 
%        http://en.wikipedia.org/wiki/Kendall_tau_rank_correlation_coefficient
%        for further explanations
%
% See also kendtau

% Version:  v0.7f
% Build:    8111216
% Date:     Nov-12 2008, 4:53 PM CET
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% try to pass input to kendtau first
try
    [tau, z, nn] = kendtau(varargin{:});
catch
    rethrow(lasterror);
end

% then compute z
nn = (1 / nn) .* z;
z = 0.5 + sqrt(2 .* z + 0.25);
z = tau ./ sqrt((10 + 4 .* z) ./ (9 .* z .* (z - 1) .* nn));
